﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace MessageRouter.Configuration
{
    public sealed class BindingConfigurationElement : ConfigurationElement
    {
        const string namePropertyName = "name";
        const string readerNamePropertyName = "reader";
        const string writerNamePropertyName = "writer";

        private static readonly ConfigurationProperty nameProperty; 
        private static readonly ConfigurationProperty readerNameProperty;
        private static readonly ConfigurationProperty writerNameProperty;
        private static readonly ConfigurationPropertyCollection properties;

        [ConfigurationProperty(namePropertyName, IsKey = true, IsRequired = true)]
        internal string Name
        {
            get { return (string)base[nameProperty]; }
        }

        [ConfigurationProperty(readerNamePropertyName, IsKey = false, IsRequired = true)]
        internal string ReaderName
        {
            get { return (string)base[readerNameProperty]; }
        }

        [ConfigurationProperty(writerNamePropertyName, IsKey = false, IsRequired = true)]
        internal string WriterName
        {
            get { return (string)base[writerNameProperty]; }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get { return properties; }
        }

        internal BindingConfigurationElement() { }

        static BindingConfigurationElement()
        {
            nameProperty = new ConfigurationProperty(namePropertyName, typeof(string), null, ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired);
            readerNameProperty = new ConfigurationProperty(readerNamePropertyName, typeof(string), null, ConfigurationPropertyOptions.IsRequired);
            writerNameProperty = new ConfigurationProperty(writerNamePropertyName, typeof(string), null, ConfigurationPropertyOptions.IsRequired);

            properties = new ConfigurationPropertyCollection
            {
                nameProperty,
                readerNameProperty,
                writerNameProperty,
            };
        }
    }
}
